package com.yihu.cms.service;


import java.io.IOException;
import java.net.MalformedURLException;

import com.yihu.beans.DerivativesDescription;
import com.yihu.dataService.hessian.mongodb.interfaceService.DerivativesDescriptionHService;
import com.yihu.dataService.hessian.resource.ResourceMongoDBManager;

public class DerivativesDescriptionService {
	
	public int add(DerivativesDescription derivativesDescription) {
		int result = 0;
		try {
			DerivativesDescriptionHService derivativesDescriptionHService = (DerivativesDescriptionHService) ResourceMongoDBManager
					.getSingleton().getBeans("derivativesDescriptionHSC");
			result = derivativesDescriptionHService.addDerivativesDescription(derivativesDescription);
		} catch (MalformedURLException e) {
			System.out.println(e.toString());
		} catch (IOException e1) {
			result = 1;
			e1.printStackTrace();
		}
		return result;
	}
	
	public int del(long id) {
		int result = 0;
		try {
			DerivativesDescriptionHService derivativesDescriptionHService = (DerivativesDescriptionHService) ResourceMongoDBManager
					.getSingleton().getBeans("derivativesDescriptionHSC");
			result = derivativesDescriptionHService.delDerivativesDescription(id);
		} catch (MalformedURLException e) {
			System.out.println(e.toString());
		} catch (IOException e1) {
			result = 1;
			e1.printStackTrace();
		}
		return result;
	}
	
	public int update(DerivativesDescription derivativesDescription) {
		int result = 0;
		try {
			DerivativesDescriptionHService derivativesDescriptionHService = (DerivativesDescriptionHService) ResourceMongoDBManager
					.getSingleton().getBeans("derivativesDescriptionHSC");
			result = derivativesDescriptionHService.updateDerivativesDescription(derivativesDescription);
		} catch (MalformedURLException e) {
			System.out.println(e.toString());
		} catch (IOException e1) {
			result = 1;
			e1.printStackTrace();
		}
		return result;
	}
	
	public DerivativesDescription getById(long id) {
		DerivativesDescription derivativesDescription = null;
		try {
			DerivativesDescriptionHService derivativesDescriptionHService = (DerivativesDescriptionHService) ResourceMongoDBManager
					.getSingleton().getBeans("derivativesDescriptionHSC");
			derivativesDescription = derivativesDescriptionHService.getDerivativesDescriptionById(id);
		} catch (MalformedURLException e) {
			System.out.println(e.toString());
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		return derivativesDescription;
	}
	
}
